  function [corcell,fmat]=correl_out( vcor , auth, spec, subf , opath, loadstr , sername ); 
% function [vdcell,fmat]=vardec_out(vdec, auth, spec, subf , opath, loadstr ); 
% Creates a cell array with the output of the Contemporaneous Correlation
% Matrix 
% Reports Means and 10% and 90% percentiles 
% 
% Inputs 
% -------
% vdec ( nz x nx x numdr )  Matrix of Variance Decompositions  
% auth 
% spec 
% subf 
% loadstr 
% Output 
% ------
% vdcell fmat 
%
% AJ 3/31/04 
cuc=cd; 
% Load series description 
% =======================
%cd(opath); 
%[junk,sername,junk]=textread('Dat.txt','%s %s %f','delimiter','\t'); 
%cd(cuc); 

[nz,nz,nd]=size(vcor); 
nsc=size(sername,1);
if nsc ~= nz 
    error('Series name and Variance Decomposition Dimension do not match') 
end
ncol=max(nz + 1 , 3 ) ; 

% Top cell with settings and descriptions 
% =======================================
cmat=emptycell(8,ncol); 
cmat(1,1:2)={'SUMMARY OF:','Correlations'}; 
cmat(2,1:2)={'______________','___________'}; 
% Empty Space 
cmat(4,1:3)={'Authors: ','Specification:','Subfolder:'}; 
cmat(5,1:3)={'=========','==============','==========='};  
cmat(6,1:3)={ auth,  spec, subf};
cmat(7,1:2)={'Loading String',loadstr}; 
cmat(8,1:3)={'See file:',['MET_SUM',spec,'_',subf,'_',loadstr],' for details'}; 

mcell=emptycell(2,ncol); 
mcell(1,1)={'Correlations'}; 
mcell(2,1:2)={'Mean','[10% , 90%]' }; 

%Compute mean of the Variance Decompositions 
%===========================================
% vdec=ipermute( vdec, [2 1 3] ); 
% Now the shocks are in rows and the series in columns 
% Mean 
vmean=mean( vcor , 3); 
%perc=[0.01;0.05;0.1;0.9;0.95;0.99]; 
% Clear all the zero entries 
%tind=find( abs( vdm(:) ) < 1e-6 ); 
%vdm(tind) =0; 

perc=[0.1;0.9]; 
perc=floor( nd*perc ); 
vperc=sort( vcor, 3); 
vperc=vperc( : ,:, perc ); 

%Report the median and 10% 90% percentile  
scell=emptycell(2*nz+1,nz+1); 
scell(1,2:end)=sername'; 
scell(1,1)={'Series'}; 
 
jj=1; % Columns   
for jj=1:nz; 
    scell(jj*2,1)=sername(jj); 
    ii=jj; % Rows  
    for ii=jj:nz; 
        scell( ii*2 , jj+1) = { sprintf( '%0.3f', vmean(ii,jj) ) };
        tlb=sprintf( '%0.3f', vperc(ii,jj,1) ); 
        tub=sprintf( '%0.3f', vperc(ii,jj,2) ); 
        tstr=['[',tlb,',',tub,']' ];
        scell( ii*2 + 1,jj+1)={ tstr };   
    end
end

corcell=[cmat;mcell;scell]; 
fmat=zeros(1,ncol);
kk=1; 
for kk=1:ncol; 
    cols=corcell(:,kk);
    fmat(kk)=size(char(cols),2); 
end
fmat(1)=-fmat(1); 
